package com.cskaoyan.day13;

public class LibraryTest {
    public static void main(String[] args) {
        Library library = new Library();
        library.addBook("C语言", "谭浩强");
        library.addBook("计算机网络第七版", "谢希仁");
        library.addBook("操作系统", "袁春风");
        library.addBook("深入理解Java虚拟机", "周志明");
        library.addBook("设计模式", "GoF");
        library.addBook("常用算法深入学习实录", "张子言");
        library.displayBooks();
    }
}

class Library {
    Book[] books = new Book[5];

    public void addBook(String title, String autho) {
        Book book = new Book(title, autho);
        boolean flag = true;
        for (int i = 0; i < books.length; i++) {
            if (books[i] == null) {
                books[i] = book;
                flag = false;
                System.out.println("《" + title + " 》已存入图书馆！");
                break;
            }
        }
        if (flag) {
            System.out.println("图书馆已经没有地方存放书籍了，放弃存入" + "《" + title + " 》");
        }
    }

    public void displayBooks() {
        for (Book book : books) {
            if (book == null) {
                continue;
            }
            System.out.println(book.displayInfo());
        }
    }

    class Book {
        private String title;
        private String autho;

        public Book(String title, String autho) {
            this.title = title;
            this.autho = autho;
        }


        public String displayInfo() {
            return "Book{" +
                    "title='" + title + '\'' +
                    ", autho='" + autho + '\'' +
                    '}';
        }
    }
}

